package com.dynaBlaster.gameElements;

import com.dynaBlaster.BoardView;
import com.dynaBlaster.DynaView;
import com.dynaBlaster.GameConfg;
import com.dynaBlaster.Point;
import com.dynaBlaster.R;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;

public class Hero extends Creature {

	int bombCount = 0;
	private Bomb justPlantedBomb;
	Direction secondaryDir = Direction.EAST;

	public Hero(DynaView board) {
		super(board);

		speed = BoardView.mTileSize / GameConfg.HERO_SPEED_FACTOR;

		IS_FLYING = false;
		IS_PASSING_CREATURES = true;

		Resources r = board.getR();
		Drawable[] nsew = new Drawable[] { r.getDrawable(R.drawable.hero_up),
				r.getDrawable(R.drawable.hero_down), r.getDrawable(R.drawable.hero_right),
				r.getDrawable(R.drawable.hero_left) };
		loadImg(nsew);

	}

	@Override
	public void move() {
		Point next = checkMoveInDirection(dir);
		if (next == null) {// check secondary
			next = checkMoveInDirection(secondaryDir);
		}

		if (next == null) {
			return; // stay
		}

		this.pos = next; // move

		// zchodzenie z nowo postawionej bomby
		if (justPlantedBomb != null && (!justPlantedBomb.isOverPoint(next))) {
			this.justPlantedBomb = null;
		}

	}

	public void setHeroDirections(Creature.Direction[] directions) {
		this.dir = directions[0];
		this.secondaryDir = directions[1];
	}

	@Override
	protected boolean checkFree(Point toCheck) {
		return board.isFree(toCheck, IS_PASSING_CREATURES, IS_FLYING, justPlantedBomb);
	}

	public void incrementBombCount() {
		bombCount++;
	}

	public void decrementBombCount() {
		bombCount--;
	}

	public boolean canPlantBomb() {
		return bombCount < GameConfg.HERO_BOMB_COUNT;
	}

	/**
	 * hero moze poruszac sie po bombie ktora wlasnie postawil, dopoki z niej
	 * nie zejdzie bez tej opcji bloowalby sie stawiajac bomby
	 * 
	 * @param bomb
	 */
	public void setJustPlantedBomb(Bomb bomb) {
		this.justPlantedBomb = bomb;

	}

}
